package tech.runchen.gz5055.oms.modules.system.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import tech.runchen.gz5055.oms.common.annotation.RequiresPermissions;
import tech.runchen.gz5055.oms.common.annotation.SysLog;
import tech.runchen.gz5055.oms.common.base.AbstractController;
import tech.runchen.gz5055.oms.common.enums.BusinessType;
import tech.runchen.gz5055.oms.common.enums.UserType;
import tech.runchen.gz5055.oms.common.utils.PageInfo;
import tech.runchen.gz5055.oms.common.utils.Result;
import tech.runchen.gz5055.oms.modules.system.entity.NoticeEntity;
import tech.runchen.gz5055.oms.modules.system.service.INoticeService;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 消息通知表 前端控制器
 * </p>
 *
 * @author zzj
 * @since 2023-11-13
 */
@Api(tags = "管理平台 - 系统通知")
@RestController
@RequestMapping("/sys/notice")
public class SysNoticeController extends AbstractController {

    @Autowired
    private INoticeService noticeService;

    @ApiOperation("系统通知列表（分页）")
    @RequiresPermissions(value = {UserType.SPD, UserType.NURSE})
    @GetMapping("/list")
    public Result list(@RequestParam Map<String, Object> params) {
        params.put("userType", getLoginUser().getUser().getType());
        params.put("userId", getUserId());
        PageInfo page = noticeService.queryPage(params);
        return Result.success(page);
    }

    @ApiOperation("系统通知列表（不分页）")
    @RequiresPermissions(value = {UserType.SPD, UserType.NURSE})
    @GetMapping("/select")
    public Result select(@RequestParam Map<String, Object> params) {
        params.put("userType", getLoginUser().getUser().getType());
        params.put("userId", getUserId());
        List<NoticeEntity> list = noticeService.querySelect(params);
        return Result.success(list);
    }

    @ApiOperation("系统通知详情")
    @RequiresPermissions()
    @GetMapping("/{noticeId}")
    public Result info(@PathVariable("noticeId") Long noticeId) {
        NoticeEntity notice = noticeService.getById(noticeId);
        return Result.success(notice);
    }

    @SysLog(title = "删除系统通知", businessType = BusinessType.DELETE)
    @ApiOperation("删除系统通知")
    @RequiresPermissions(value = {UserType.SPD, UserType.NURSE})
    @DeleteMapping("/delete/{noticeId}")
    public Result delete(@PathVariable("noticeId") Long noticeId) {
        noticeService.deleteNotice(getUserId(), noticeId);
        return Result.success();
    }
}
